import { connector as http } from '@zh/common-utils/http'

export function connectorList (id) {
  return http.get(`/list`)
}

export function connectorInfo (id) {
  return http.get(`/info/${id}`)
}

export function saveOrUpdateFormInfo (params) {
  if (params.id) {
    return http.post('/update', params)
  } else {
    return http.post('/save', params)
    // return http.post('/form/save', params)
  }
}
export function connectorPage (params) {
  return http.post('/page', params)
}

export function connectorDelete (params) {
  return http.post('/deleteIds', params)
}
export function connectorDeleteById (params) {
  return http.post('/deleteById', params)
}
export function connectorUpdateState (params) {
  return http.post('/updateState', params)
}

export function connectorinterfacePage (params) {
  return http.post('/connectorinterface/page', params)
}

export function saveOrUpdate (params) {
  if (params.connectorInterfaceVo.id) {
    return http.post('/connectorinterface/interfaceManageUpdate', params)
  } else {
    return http.post('/connectorinterface/addInterfaceAndParamter', params)
  }
}

export function connectorinterfaceDeleteIds (params) {
  return http.post('/connectorinterface/deleteIds', params)
}

export function connectorinterfaceInfo (id) {
  return http.get(`/connectorinterface/info/${id}`)
}

export function buildData (params) {
  return http.post('/connectorinterfaceparameter/buildData', params)
}

export function queryInterfaceAndParamterData (id) {
  return http.get(`/connectorinterface/queryInterfaceAndParamterData/${id}`)
}

export function updateState (params) {
  return http.post('/connectorinterface/update', params)
}

// 接口自定义参数
export function customParameter (params) {
  return http.post('/connectorinterface/customParameter', params)
}
// 执行接口流程
export function execInterface (id) {
  return http.get(`/connectorinterface/execInterface?interfaceId=${id}`)
}
// 添加/编辑保存分组、连接器
export function saveOrUpdateConnector (params) {
  if (params.id) {
    return http.post('/connector/update', params)
  } else {
    return http.post('/connector/save', params)
  }
}

// 获取连接器树形菜单数据
export function fetchConnectorTree (params) {
  return http.get(`/connector/tree?name=${params.name}`)
}

// 按照分组查找连接器列表数据
export function fetchConnectorPage (params) {
  return http.post('/connector/page', params)
}

// 更新连接器状态
export function fetchConnectorUpdateState (params) {
  return http.post('/connector/updateState', params)
}

// 根据连接器查询接口列表
export function fetchAPIListbyConnector (params) {
  return http.get(`/connector/instance/list?connectorId=${params.connectorId}`)
}

// 获取部署节点下拉列表
export function fetchDeploymentNodeList (params) {
  return http.get('/connector/getDeploymentNode')
}

// 获取连接器详情
export function fetchConnectorInfo (id) {
  return http.get(`/connector/info/${id}`)
}

// 删除分组，连接器
export function fetchDeleteGroup (id) {
  return http.get(`/connector/deleteById?connectorId=${id}`)
}

// 添加/编辑，连接器接口
export function fetchSaveConnectorInstance (params) {
  if (params?.interfaceAndParamterVo?.connectorInterfaceVo.id) {
    return http.post('/connector/instance/update', params)
  } else {
    return http.post('/connector/instance/add', params)
  }
}

// 删除连接器接口
export function fetchDeleteInstance (id, type) {
  return http.get(`/connector/instance/deleteById?id=${id}&type=${type}`)
}

// 查询连接器实例详情
export function fetchInstanceInfo (id, type) {
  return http.get(`/connector/instance/queryDetail?id=${id}&type=${type}`)
}
